package com.sgb.kjwl.view.ui.fragment.enterprise;


import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.sgb.kjwl.AppLazyFragment;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.NeedFragmentBinding;
import com.sgb.kjwl.di.home.DaggerHomeFragComponent;
import com.sgb.kjwl.di.home.HomeFragModule;
import com.sgb.kjwl.model.entity.Bean;
import com.sgb.kjwl.model.entity.ParentAreaEntity;
import com.sgb.kjwl.model.entity.ServiceBean;
import com.sgb.kjwl.model.entity.enterprise.IpPickSelectEntity;
import com.sgb.kjwl.model.entity.enterprise.ListBean;
import com.sgb.kjwl.pop.NeedPopWindow;
import com.sgb.kjwl.utils.PickPriceUtils;
import com.swgk.core.util.UiUtil;
import com.swgk.core.event.EventConstant;
import com.sgb.kjwl.view.event.LoginEvent;
import com.sgb.kjwl.view.event.SearchEvent;
import com.sgb.kjwl.view.ui.activity.enterprise.NewNeedDetailsActivity;
import com.sgb.kjwl.view.ui.adapter.enterprise.NeedNewAdapter;
import com.sgb.kjwl.view.ui.adapter.enterprise.NeedSelectAdapter;
import com.sgb.kjwl.view.widget.IpPopWindow;
import com.sgb.kjwl.view.widget.NeedFragmentServicePopWindow;
import com.sgb.kjwl.viewmodel.home.NeedModel;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.customview.ScreenTextView;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;
import com.swgk.core.xrecyclerview.XRecyclerView;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;

/**
 * 作者:张磊
 * 日期:2020/3/18 0024
 * 说明:需求大厅
 * 将加载方式替换为懒加载
 */
public class NeedFragment extends AppLazyFragment {


    @Inject
    NeedModel mModel;

    private NeedFragmentBinding mBinding;
    private NeedPopWindow mNeedPopWindow;
    private NeedSelectAdapter mAdapter;
    private ScreenTextView mScreenTextView;
    private List<Bean> mDatas1;
    private List<Bean> mDatas2;
    private List<Bean> mDatas3;
    private List<Bean> mDatas4;
    private List<Bean> mDatas5;
    private List<Bean> mDatas6;
    private List<Bean> mDatas7;
    private List<Bean> mDatas8;
    private List<Bean> mDatas9;
    private List<Bean> mDatas10;
    private List<Bean> mDatas11;
    private List<Bean> mDatas12;
    private List<Bean> mDatas13;
    private List<Bean> mDatas14;


    private int mIndex = 1;
    private int mIndexPage = 1;

    private NeedNewAdapter mNeedAdapter;
    private Map<String, Object> mMap;
    private Activity mActivity;

    private IpPopWindow teamForEnterpisePopWindow_price;
    private IpPopWindow typePopWindow;
    private IpPopWindow oldPopWindow;
    private List<IpPickSelectEntity> priceDatas = new ArrayList<>();
    private List<IpPickSelectEntity> assestTypeDatas = new ArrayList<>();
    private List<IpPickSelectEntity> assestOldDatas = new ArrayList<>();
    private boolean isChange3 = false;


    private NeedFragmentServicePopWindow servicePopWindow;
    private List<ParentAreaEntity<List<ParentAreaEntity<List<ParentAreaEntity>>>>> parentList = new ArrayList<>();
    private boolean ischange4 = false;
    private boolean ischange5 = false;
    private boolean ischange6 = false;

    private String categoryFirstId = "";
    private String categorySecondId = "";
    private String categoryThirdId = "";
    private String minPrice = "";
    private String maxPrice = "";
    private String category = "";


    public static NeedFragment newInstance(String position, String category) {
        NeedFragment fragment = new NeedFragment();
        Bundle bundle = new Bundle();
        bundle.putString("data", position);
        bundle.putString("category", category);
        fragment.setArguments(bundle);
        return fragment;
    }

    public static NeedFragment newInstance(String position, String category, String websiteNo, String websiteType) {
        NeedFragment fragment = new NeedFragment();
        Bundle bundle = new Bundle();
        bundle.putString("data", position);
        bundle.putString("category", category);
        bundle.putString("websiteNo", websiteNo);
        bundle.putString("websiteType", websiteType);
        fragment.setArguments(bundle);
        return fragment;
    }

    public static NeedFragment newInstance(String position) {
        NeedFragment fragment = new NeedFragment();
        Bundle bundle = new Bundle();
        bundle.putString("data", position);
        fragment.setArguments(bundle);
        return fragment;
    }


    @Override
    protected void setupFragmentComponent(AppComponent appComponent) {
        DaggerHomeFragComponent.builder()
                .appComponent(appComponent)
                .homeFragModule(new HomeFragModule(this))
                .build()
                .inject(this);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mBinding = DataBindingUtil.inflate(inflater, R.layout.need_fragment, container, false);
        return mBinding.getRoot();
    }


    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
        mActivity = getActivity();
        mModel.getDemandHallList(mMap);
    }

    @Override
    protected void initView() {
        super.initView();

        mNeedPopWindow = new NeedPopWindow(getActivity());
        mNeedPopWindow.setBgView(mBinding.grayLayout);
        mNeedPopWindow.setBackground(R.color.white);

        LinearLayoutManager manager = new LinearLayoutManager(getActivity());
        manager.setOrientation(RecyclerView.HORIZONTAL);
        mBinding.rvSelect.setLayoutManager(manager);
//        mBinding.rvSelect.setLayoutManager(new GridLayoutManager(UiUtil.getContext(), 4));
        mAdapter = new NeedSelectAdapter(getContext(), null);
        mNeedAdapter = new NeedNewAdapter(getActivity(), null);
        mBinding.rvSelect.setAdapter(mAdapter);
        mBinding.displayView.setLayoutManager(new LinearLayoutManager(UiUtil.getContext()));
        mBinding.displayView.setLoadingMoreEnabled(true);
        mBinding.displayView.setAdapter(mNeedAdapter);

        teamForEnterpisePopWindow_price = new IpPopWindow(getActivity());
        teamForEnterpisePopWindow_price.setBgView(mBinding.grayLayout);
        teamForEnterpisePopWindow_price.setBackground(R.color.white);
        teamForEnterpisePopWindow_price.setOnResultClick((type, key2, key3) -> {
            mIndexPage = 1;
            mMap.put("pageSize", mIndexPage);
            mMap.put("requirementTypes", mIndex);

            if (!((IpPickSelectEntity) type).getName().equals("不限")) {
                isChange3 = true;
//                if (!((IpPickSelectEntity) type).getMaxPrice().equals("") && !((IpPickSelectEntity) type).getMaxPrice().equals("0"))
//                     = ((IpPickSelectEntity) type).getMaxPrice() + "0000";
//                if (!((IpPickSelectEntity) type).getMinPrice().equals("") && !((IpPickSelectEntity) type).getMinPrice().equals("0"))
//                    minPrice =  ((IpPickSelectEntity) type).getMinPrice() + "0000";
                maxPrice = PickPriceUtils.getMaxPrice((IpPickSelectEntity) type);
                minPrice = PickPriceUtils.getMinPrice((IpPickSelectEntity) type);
                mScreenTextView.contentSelectRed(true, false);

                mMap.put("maxPrice", maxPrice);
                mMap.put("minPrice", minPrice);

            } else {
                minPrice = "";
                maxPrice = "";
                mMap.remove("maxPrice");
                mMap.remove("minPrice");
                isChange3 = false;
                mScreenTextView.contentSelectRed(false, false);
            }
            mModel.getDemandHallList(mMap);
        });

        teamForEnterpisePopWindow_price.setOnDismissListener(() -> {
            if (isChange3) {
                mScreenTextView.contentSelectRed(true, false);
            } else {
                mScreenTextView.contentSelectRed(false, false);
            }
        });

        typePopWindow = new IpPopWindow(getActivity());
        typePopWindow.setBgView(mBinding.grayLayout);
        typePopWindow.setBackground(R.color.white);
        typePopWindow.setOnResultClick((type, key2, key3) -> {
            mIndexPage = 1;
            mMap.put("pageSize", mIndexPage);
            mMap.put("requirementTypes", mIndex);

            mMap.remove("assetsOldNew");
            ischange6 = false;
            if (oldPopWindow != null) {
                oldPopWindow.setDefItem(0);
            }
            if (mBinding.rvSelect.getChildCount() > 2) {
                ((ScreenTextView) mBinding.rvSelect.getChildAt(2)).contentSelectRed(false, false);
            }

            if (!((IpPickSelectEntity) type).getName().equals("不限")) {
                ischange5 = true;
                mScreenTextView.contentSelectRed(true, false);
                mMap.put("assetsType", ((IpPickSelectEntity) type).getValue());
            } else {
                ischange5 = false;
                mScreenTextView.contentSelectRed(false, false);
                mMap.put("assetsType", "");
            }
            if (((IpPickSelectEntity) type).getRelateOld() != null && ((IpPickSelectEntity) type).getRelateOld().equals("0")) {
                if (mAdapter != null && !mAdapter.getDatas().contains("资产新旧"))
                    mAdapter.addData("资产新旧");
            } else {
                if (mAdapter != null && mAdapter.getDatas().size() > 2) {
                    mAdapter.removeItem(2);
                }
            }
            mModel.getDemandHallList(mMap);
        });
        typePopWindow.setOnDismissListener(() -> {
            if (mScreenTextView != null)
                if (ischange5) {
                    mScreenTextView.contentSelectRed(true, false);
                } else {
                    mScreenTextView.contentSelectRed(false, false);
                }
        });

        oldPopWindow = new IpPopWindow(getActivity());
        oldPopWindow.setBgView(mBinding.grayLayout);
        oldPopWindow.setBackground(R.color.white);
        oldPopWindow.setOnResultClick((type, key2, key3) -> {
            mIndexPage = 1;
            mMap.put("pageSize", mIndexPage);
            mMap.put("requirementTypes", mIndex);

            if (!((IpPickSelectEntity) type).getName().equals("不限")) {
                ischange6 = true;
                mScreenTextView.contentSelectRed(true, false);
                mMap.put("assetsOldNew", ((IpPickSelectEntity) type).getId());
            } else {
                ischange6 = false;
                mScreenTextView.contentSelectRed(false, false);
                mMap.put("assetsOldNew", ((IpPickSelectEntity) type).getId());
            }
            mModel.getDemandHallList(mMap);
        });
        oldPopWindow.setOnDismissListener(() -> {
            if (mScreenTextView != null)
                if (ischange6) {
                    mScreenTextView.contentSelectRed(true, false);
                } else {
                    mScreenTextView.contentSelectRed(false, false);
                }
        });

        servicePopWindow = new NeedFragmentServicePopWindow(getActivity());
        servicePopWindow.setBgView(mBinding.grayLayout);

        servicePopWindow.setOnResultClick((key1, key2, key3) -> {

            ServiceBean serviceBean = (ServiceBean) key2;
            ischange4 = !serviceBean.getParentNo().equals("");
            mIndexPage = 1;
            mMap.put("pageSize", mIndexPage);
            mMap.put("requirementTypes", mIndex);
            if (ischange4) {
                categoryFirstId = serviceBean.getParentNo();
                categorySecondId = serviceBean.getChildNo();
                categoryThirdId = serviceBean.getThridNo();
                mMap.put("categoryFirstId", categoryFirstId);
                mMap.put("categorySecondId", categorySecondId);
                mMap.put("categoryThirdId", categoryThirdId);
                mScreenTextView.contentSelectRed(true, false);
            } else {
                categoryFirstId = "";
                categorySecondId = "";
                categoryThirdId = "";
                mMap.remove("categoryFirstId");
                mMap.remove("categorySecondId");
                mMap.remove("categoryThirdId");
                mScreenTextView.contentSelectRed(false, false);
            }
            mModel.getDemandHallList(mMap);
        });
        servicePopWindow.setOnDismissListener(() -> {
            if (ischange4) {
                mScreenTextView.contentSelectRed(true, false);
            } else {
                servicePopWindow.showMoren();
                mScreenTextView.contentSelectRed(false, false);
            }
        });

        initData();
        initListener();
    }

    private void initData() {
        Bundle arguments = getArguments();
        String data = arguments.getString("data");
        category = arguments.getString("category");
        mModel.websiteNo = getArguments().getString("websiteNo");
        mModel.websiteType = getArguments().getString("websiteType");
        if (mMap == null) {
            mMap = new HashMap<>();
        }
        mMap.put("pageSize", mIndexPage);
        mMap.put("limit", 20);
        List<String> beans = new ArrayList<>();
        if (data.contains("商标")) {
            mIndex = 1;
            beans.clear();
            beans.add("商标分类");
            beans.add("预算价格");
            mAdapter.setDatas(beans);
            mBinding.rvSelect.setAdapter(mAdapter);
            mMap.put("requirementTypes", 1);
            if (!TextUtils.isEmpty(category)) {
                mMap.put("categoryNo", category);
                mBinding.rvSelect.getChildCount();
            }
        } else if (data.contains("专利")) {
            mIndex = 2;
            beans.clear();
            beans.add("领域分类");
            beans.add("专利类型");
            beans.add("专利状态");
            beans.add("预算价格");
            mMap.put("requirementTypes", 2);
            mAdapter.setDatas(beans);
            mBinding.rvSelect.setAdapter(mAdapter);
            if (!TextUtils.isEmpty(category)) {
                mMap.put("patentType", category);
            }
        } else if (data.contains("版权")) {
            mIndex = 3;
            beans.clear();
            beans.add("版权分类");
            beans.add("授权方式");
            beans.add("预算价格");
            mAdapter.setDatas(beans);
            mBinding.rvSelect.setAdapter(mAdapter);
            mMap.put("requirementTypes", 3);
            if (!TextUtils.isEmpty(category)) {
                mMap.put("classificationCopyright", category);
            }
        } else if (data.contains("公司")) {
            mIndex = 4;
            beans.clear();
            beans.add("行业类型");
            beans.add("企业类型");
            beans.add("纳税规模");
            beans.add("预算价格");
            mAdapter.setDatas(beans);
            mBinding.rvSelect.setAdapter(mAdapter);
            mMap.put("requirementTypes", 4);
            if (!TextUtils.isEmpty(category)) {
                mMap.put("industryTypeId", category);
            }
        } else if (data.contains("服务")) {
            mIndex = 5;
            beans.clear();
            beans.add("服务分类");
            beans.add("服务主体");
            beans.add("预算价格");
            mAdapter.setDatas(beans);
            mBinding.rvSelect.setAdapter(mAdapter);
            mMap.put("requirementTypes", 5);
            if (!TextUtils.isEmpty(category)) {
                mMap.put("categoryFirstId", category);
            }
        } else if (data.contains("资产")) {
            mIndex = 6;
            beans.clear();
            beans.add("资产类型");
            beans.add("预算价格");
            mAdapter.setDatas(beans);
            mBinding.rvSelect.setAdapter(mAdapter);
            mMap.put("requirementTypes", 6);
            if (!TextUtils.isEmpty(category)) {
                mMap.put("assetsType", category);
            }
        }
    }

    private void initListener() {
//        mNeedAdapter.setmAskClick(item -> {
//            if (DialogHelper.checkLogin()) {
//                DialogHelper.showDialog(getContext(), "确认呼叫", item.linkMan + "：" + item.linkmanPhone, "确定", new DialogFunction() {
//                    @Override
//                    public void normalRoundDialog() {
//                        ActivityJump.jumpToPhone(getContext(), item.linkmanPhone);
//                    }
//                });
//            } else {
//                DialogHelper.showLoginDialogNew(getContext(), EventConstant.EVENT_NEED_FRG_JUMP, "温馨提示", "登录后可拨打电话,去登录", "登录");
//            }
//        });

        mNeedPopWindow.setOnDismissListener(() -> {
            mScreenTextView.contentSelectRed(
                    mNeedPopWindow.mType == 1 ?
                            mNeedPopWindow.mPos1 != 0 : mNeedPopWindow.mType == 2 ?
                            mNeedPopWindow.mPos2 != 0 : mNeedPopWindow.mType == 3 ?
                            mNeedPopWindow.mPos3 != 0 : mNeedPopWindow.mType == 4 ?
                            mNeedPopWindow.mPos4 != 0 : mNeedPopWindow.mType == 5 ?
                            mNeedPopWindow.mPos5 != 0 : mNeedPopWindow.mType == 6 ?
                            mNeedPopWindow.mPos6 != 0 : mNeedPopWindow.mType == 7 ?
                            mNeedPopWindow.mPos7 != 0 : mNeedPopWindow.mType == 8 ?
                            mNeedPopWindow.mPos8 != 0 : mNeedPopWindow.mType == 9 ?
                            mNeedPopWindow.mPos9 != 0 : mNeedPopWindow.mType == 10 ?
                            mNeedPopWindow.mPos10 != 0 : mNeedPopWindow.mType == 11 ?
                            mNeedPopWindow.mPos11 != 0 : mNeedPopWindow.mType == 12 ?
                            mNeedPopWindow.mPos12 != 0 : mNeedPopWindow.mType == 13 ?
                            mNeedPopWindow.mPos13 != 0 : mNeedPopWindow.mType == 14 ?
                            mNeedPopWindow.mPos14 != 0 : mNeedPopWindow.mType == 15 ?
                            mNeedPopWindow.mPos15 != 0 : mNeedPopWindow.mType == 16 ?
                            mNeedPopWindow.mPos16 != 0 : mNeedPopWindow.mPos17 != 0
                    , false);
            if (!mNeedPopWindow.mIsClick)
                return;
            mNeedPopWindow.mIsClick = false;
            mIndexPage = 1;
            mMap.put("pageSize", mIndexPage);
            mMap.put("requirementTypes", mIndex);
            switch (mIndex) {
                case 1:
                    // 商标
                    mMap.put("areaClassification", null);
                    mMap.put("patentType", null);
                    mMap.put("classificationCopyright", null);
                    mMap.put("authorizationWay", null);
                    mMap.put("industryTypeId", null);
                    mMap.put("enterpriseTypeId", null);
                    mMap.put("taxScale", null);
                    mMap.put("categoryNo", mNeedPopWindow.mPos1 != 0 ? mDatas1.get(mNeedPopWindow.mPos1).no : null);
//                    mMap.put("minPrice", mNeedPopWindow.mPos2 != 0 ? mNeedPopWindow.mPos2 == 1 ? "-1" : mNeedPopWindow.mPos2 == 2 ? "0" :
//                            mNeedPopWindow.mPos2 == 3 ? "10000" : "50000" : null);
//                    mMap.put("maxPrice", mNeedPopWindow.mPos2 != 0 ? mNeedPopWindow.mPos2 == 1 ? "-1" : mNeedPopWindow.mPos2 == 2 ? "10000" :
//                            mNeedPopWindow.mPos2 == 3 ? "50000" : null : null);
                    if (isChange3) {
                        if (!TextUtils.isEmpty(maxPrice)) mMap.put("maxPrice", maxPrice);
                        else mMap.remove("maxPrice");

                        if (!TextUtils.isEmpty(minPrice)) mMap.put("minPrice", minPrice);
                        else mMap.remove("minPrice");
                    }
                    break;
                case 2:
                    // 专利
                    mMap.put("categoryNo", null);
                    mMap.put("classificationCopyright", null);
                    mMap.put("authorizationWay", null);
                    mMap.put("industryTypeId", null);
                    mMap.put("enterpriseTypeId", null);
                    mMap.put("taxScale", null);
                    mMap.put("areaClassification", mNeedPopWindow.mPos3 != 0 ? mDatas3.get(mNeedPopWindow.mPos3).no : null);
                    mMap.put("patentType", mNeedPopWindow.mPos4 != 0 ? mDatas4.get(mNeedPopWindow.mPos4).id : null);
                    mMap.put("patentStatus", mNeedPopWindow.mPos5 != 0 ? mNeedPopWindow.mPos5 == 1 ? "0" : "1" : null);
//                    mMap.put("minPrice", mNeedPopWindow.mPos6 != 0 ? mNeedPopWindow.mPos6 == 1 ? "-1" :
//                            mNeedPopWindow.mPos6 == 2 ? "0" : mNeedPopWindow.mPos6 == 3 ? "10000" : "50000" : null);
//                    mMap.put("maxPrice", mNeedPopWindow.mPos6 != 0 ? mNeedPopWindow.mPos6 == 1 ? "-1" : mNeedPopWindow.mPos6 == 2 ? "10000"
//                            : mNeedPopWindow.mPos6 == 3 ? "50000" : null : null);
                    if (isChange3) {
                        if (!TextUtils.isEmpty(maxPrice)) mMap.put("maxPrice", maxPrice);
                        else mMap.remove("maxPrice");

                        if (!TextUtils.isEmpty(minPrice)) mMap.put("minPrice", minPrice);
                        else mMap.remove("minPrice");
                    }
                    break;
                case 3:
                    // 版权
                    mMap.put("categoryNo", null);
                    mMap.put("areaClassification", null);
                    mMap.put("patentType", null);
                    mMap.put("industryTypeId", null);
                    mMap.put("enterpriseTypeId", null);
                    mMap.put("taxScale", null);
                    mMap.put("classificationCopyright", mNeedPopWindow.mPos7 != 0 ? mDatas7.get(mNeedPopWindow.mPos7).no : null);
                    mMap.put("authorizationWay", mNeedPopWindow.mPos8 != 0 ? mNeedPopWindow.mPos8 == 1 ? "1" : "2" : null);
//                    mMap.put("minPrice", mNeedPopWindow.mPos9 != 0 ? mNeedPopWindow.mPos9 == 1 ? "-1" : mNeedPopWindow.mPos9 == 2 ? "0" : "10000" : null);
//                    mMap.put("maxPrice", mNeedPopWindow.mPos9 != 0 ? mNeedPopWindow.mPos9 == 1 ? "-1" : mNeedPopWindow.mPos9 == 2 ? "10000" : null : null);
                    if (isChange3) {
                        if (!TextUtils.isEmpty(maxPrice)) mMap.put("maxPrice", maxPrice);
                        else mMap.remove("maxPrice");

                        if (!TextUtils.isEmpty(minPrice)) mMap.put("minPrice", minPrice);
                        else mMap.remove("minPrice");
                    }
                    break;
                case 4:
                    // 公司
                    mMap.put("categoryNo", null);
                    mMap.put("areaClassification", null);
                    mMap.put("patentType", null);
                    mMap.put("classificationCopyright", null);
                    mMap.put("authorizationWay", null);
                    mMap.put("industryTypeId", mNeedPopWindow.mPos10 != 0 ? mDatas10.get(mNeedPopWindow.mPos10).no : null);
                    mMap.put("enterpriseTypeId", mNeedPopWindow.mPos11 != 0 ? mNeedPopWindow.mPos11 == 1 ? "0" : mNeedPopWindow.mPos11 == 2 ? "1" : mNeedPopWindow.mPos11 == 3 ? "2" : "3" : null);
                    mMap.put("taxScale", mNeedPopWindow.mPos12 != 0 ? mNeedPopWindow.mPos12 == 1 ? "0" : mNeedPopWindow.mPos12 == 2 ? "1" : mNeedPopWindow.mPos12 == 3 ? "2" : "3" : null);
//                    mMap.put("minPrice", mNeedPopWindow.mPos13 != 0 ? mNeedPopWindow.mPos13 == 1 ? "-1" :
//                            mNeedPopWindow.mPos13 == 2 ? "0" : mNeedPopWindow.mPos13 == 3 ? "10000" :
//                                    mNeedPopWindow.mPos13 == 4 ? "20000" :
//                                            "100000" : null);
//                    mMap.put("maxPrice", mNeedPopWindow.mPos13 != 0 ? mNeedPopWindow.mPos13 == 1 ? "-1" :
//                            mNeedPopWindow.mPos13 == 2 ? "10000" : mNeedPopWindow.mPos13 == 3 ? "20000" :
//                                    mNeedPopWindow.mPos13 == 4 ? "100000" :
//                                            null : null);
                    if (isChange3) {
                        if (!TextUtils.isEmpty(maxPrice)) mMap.put("maxPrice", maxPrice);
                        else mMap.remove("maxPrice");

                        if (!TextUtils.isEmpty(minPrice)) mMap.put("minPrice", minPrice);
                        else mMap.remove("minPrice");
                    }
                    break;

                case 5://服务

                    if (mNeedPopWindow.mPos14 != 0) {
                        mMap.put("servicePrincipal", mNeedPopWindow.mPos14 == 1 ? 2 : 1);
                    } else {
                        mMap.remove("servicePrincipal");
                    }
                    if (ischange4) {
                        mMap.put("categoryFirstId", categoryFirstId);
                        mMap.put("categorySecondId", categorySecondId);
                        mMap.put("categoryThirdId", categoryThirdId);
                    }
                    if (isChange3) {
                        if (!TextUtils.isEmpty(maxPrice)) mMap.put("maxPrice", maxPrice);
                        else mMap.remove("maxPrice");

                        if (!TextUtils.isEmpty(minPrice)) mMap.put("minPrice", minPrice);
                        else mMap.remove("minPrice");
                    }
                    break;
            }
            mModel.getDemandHallList(mMap);
        });
        mNeedAdapter.setOnItemClick(new AdapterOnItemClick<ListBean>() {
            @Override
            public void onItemClick(ListBean listBean, int position) {
                NewNeedDetailsActivity.startactivity(getActivity(), listBean.id + "");


            }
        });
        mBinding.displayView.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                mIndexPage = 1;
                mMap.put("pageSize", mIndexPage);
                mModel.getDemandHallList(mMap);
            }

            @Override
            public void onLoadMore() {
                mIndexPage++;
                mMap.put("pageSize", mIndexPage);
                mModel.getDemandHallList(mMap);
            }
        });

        mAdapter.setOnItemClick(new AdapterOnItemClick<String>() {
            @Override
            public void onItemClick(String s, int position) {
                mScreenTextView = (ScreenTextView) mBinding.rvSelect.getChildAt(position);
                mScreenTextView.contentSelectRed(false, true);
                String type = mScreenTextView.getText();
                switch (mIndex) {
                    case 1:
                        if (type.contains("商标分类")) {
                            mNeedPopWindow.mType = 1;
                            if (mDatas1 == null) {
                                mDatas1 = new ArrayList<>();
                                mModel.getTrademarkTypeOption();
                            } else {
                                mNeedPopWindow.setData(mDatas1);
                                showPop();
                            }
                            if (mNeedPopWindow.mAdapter != null) {
                                mNeedPopWindow.mAdapter.setDefItem(mNeedPopWindow.mPos1);
                            }
                        } else {
//                        mNeedPopWindow.mType = 2;
//                        if (mDatas2 == null) {
//                            mDatas2 = new ArrayList<>();
//                            mDatas2.add(new Bean("不限"));
//                            mDatas2.add(new Bean("议价"));
//                            mDatas2.add(new Bean("1万以下"));
//                            mDatas2.add(new Bean("1-5万"));
//                            mDatas2.add(new Bean("5万以上"));
//                        }
//                        mNeedPopWindow.setData(mDatas2);
//                        if (mNeedPopWindow.mAdapter != null) {
//                            mNeedPopWindow.mAdapter.setDefItem(mNeedPopWindow.mPos2);
//                        }
//                        showPop();
                            if (priceDatas.size() == 0) {
                                mModel.getSereicePrice(4);
                            } else {
                                if (!teamForEnterpisePopWindow_price.isShowing()) {
                                    teamForEnterpisePopWindow_price.showPopwindow(mBinding.rvSelect, 0, 0);
                                }
                            }
                        }
                        break;
                    case 2:
                        if (type.contains("领域分类")) {
                            mNeedPopWindow.mType = 3;
                            if (mDatas3 == null) {
                                mDatas3 = new ArrayList<>();
                                mModel.getAllCopyright();
                            } else {
                                mNeedPopWindow.setData(mDatas3);
                                showPop();
                            }
                            if (mNeedPopWindow.mAdapter != null) {
                                mNeedPopWindow.mAdapter.setDefItem(mNeedPopWindow.mPos3);
                            }
                        } else if (type.contains("专利类型")) {
                            // TODO: 2020/12/29 0029
                            mNeedPopWindow.mType = 4;
                            if (mDatas4 == null) {
                                mDatas4 = new ArrayList<>();
                                mModel.getPatentTypeOption();
                            } else {
                                mNeedPopWindow.setData(mDatas4);
                                showPop();
                            }
                            if (mNeedPopWindow.mAdapter != null) {
                                mNeedPopWindow.mAdapter.setDefItem(mNeedPopWindow.mPos4);
                            }

                        } else if (type.contains("专利状态")) {
                            mNeedPopWindow.mType = 5;
                            if (mDatas5 == null) {
                                mDatas5 = new ArrayList<>();
                                mDatas5.add(new Bean("不限"));
                                mDatas5.add(new Bean("授权未下证"));
                                mDatas5.add(new Bean("授权已下证"));
                            }
                            mNeedPopWindow.setData(mDatas5);
                            if (mNeedPopWindow.mAdapter != null) {
                                mNeedPopWindow.mAdapter.setDefItem(mNeedPopWindow.mPos5);
                            }
                            showPop();

                        } else {
//                        mNeedPopWindow.mType = 6;
//                        if (mDatas6 == null) {
//                            mDatas6 = new ArrayList<>();
//                            mDatas6.add(new Bean("不限"));
//                            mDatas6.add(new Bean("议价"));
//                            mDatas6.add(new Bean("1万以下"));
//                            mDatas6.add(new Bean("1-5万"));
//                            mDatas6.add(new Bean("5万以上"));
//                        }
//                        mNeedPopWindow.setData(mDatas6);
//                        if (mNeedPopWindow.mAdapter != null) {
//                            mNeedPopWindow.mAdapter.setDefItem(mNeedPopWindow.mPos6);
//                        }
//                        showPop();
                            if (priceDatas.size() == 0) {
                                mModel.getSereicePrice(5);
                            } else {
                                if (!teamForEnterpisePopWindow_price.isShowing()) {
                                    mBinding.rvSelect.smoothScrollToPosition(mAdapter.getItemCount() - 1);
                                    teamForEnterpisePopWindow_price.showPopwindow(mBinding.rvSelect, 0, 0);
                                }
                            }

                        }

                        break;
                    case 3:
                        if (type.contains("版权分类")) {
                            mNeedPopWindow.mType = 7;
                            if (mDatas7 == null) {
                                mDatas7 = new ArrayList<>();
                                mModel.getAllQualification();
                            } else {
                                mNeedPopWindow.setData(mDatas7);
                                showPop();
                            }
                            if (mNeedPopWindow.mAdapter != null) {
                                mNeedPopWindow.mAdapter.setDefItem(mNeedPopWindow.mPos7);
                            }

                        } else if (type.contains("授权方式")) {
                            mNeedPopWindow.mType = 8;
                            if (mDatas8 == null) {
                                mDatas8 = new ArrayList<>();
                                mDatas8.add(new Bean("不限"));
                                mDatas8.add(new Bean("独家授权"));
                                mDatas8.add(new Bean("非独家授权"));
                            }
                            mNeedPopWindow.setData(mDatas8);
                            if (mNeedPopWindow.mAdapter != null) {
                                mNeedPopWindow.mAdapter.setDefItem(mNeedPopWindow.mPos8);
                            }
                            showPop();
                        } else {
//                        mNeedPopWindow.mType = 9;
//                        if (mDatas9 == null) {
//                            mDatas9 = new ArrayList<>();
//                            mDatas9.add(new Bean("不限"));
//                            mDatas9.add(new Bean("议价"));
//                            mDatas9.add(new Bean("1万以下"));
//                            mDatas9.add(new Bean("1万以上"));
//                        }
//                        mNeedPopWindow.setData(mDatas9);
//                        if (mNeedPopWindow.mAdapter != null) {
//                            mNeedPopWindow.mAdapter.setDefItem(mNeedPopWindow.mPos9);
//                        }
//                        showPop();

                            if (priceDatas.size() == 0) {
                                mModel.getSereicePrice(6);
                            } else {
                                if (!teamForEnterpisePopWindow_price.isShowing()) {
                                    teamForEnterpisePopWindow_price.showPopwindow(mBinding.rvSelect, 0, 0);
                                }
                            }
                        }
                        break;
                    case 4:
                        if (type.contains("行业类型")) {
                            mNeedPopWindow.mType = 10;
                            if (mDatas10 == null) {
                                mDatas10 = new ArrayList<>();
                                mModel.getAllSserviceCategory();
                            } else {
                                mNeedPopWindow.setData(mDatas10);
                                showPop();
                            }
                            if (mNeedPopWindow.mAdapter != null) {
                                mNeedPopWindow.mAdapter.setDefItem(mNeedPopWindow.mPos10);
                            }
                        } else if (type.contains("企业类型")) {
                            mNeedPopWindow.mType = 11;
                            if (mDatas11 == null) {
                                mDatas11 = new ArrayList<>();
                                mDatas11.add(new Bean("不限"));
                                mDatas11.add(new Bean("有限责任公司"));
                                mDatas11.add(new Bean("个人独资公司"));
                                mDatas11.add(new Bean("港澳台公司"));
                                mDatas11.add(new Bean("集团公司"));
                            }
                            mNeedPopWindow.setData(mDatas11);
                            if (mNeedPopWindow.mAdapter != null) {
                                mNeedPopWindow.mAdapter.setDefItem(mNeedPopWindow.mPos11);
                            }
                            showPop();

                        } else if (type.contains("纳税规模")) {
                            mNeedPopWindow.mType = 12;
                            if (mDatas12 == null) {
                                mDatas12 = new ArrayList<>();
                                mDatas12.add(new Bean("不限"));
                                mDatas12.add(new Bean("小规模"));
                                mDatas12.add(new Bean("一般纳税人"));
                                mDatas12.add(new Bean("出口纳税人"));
                                mDatas12.add(new Bean("未核税"));
                            }
                            mNeedPopWindow.setData(mDatas12);
                            if (mNeedPopWindow.mAdapter != null) {
                                mNeedPopWindow.mAdapter.setDefItem(mNeedPopWindow.mPos12);
                            }
                            showPop();

                        } else {
//                        mNeedPopWindow.mType = 13;
//                        if (mDatas13 == null) {
//                            mDatas13 = new ArrayList<>();
//                            mDatas13.add(new Bean("不限"));
//                            mDatas13.add(new Bean("议价"));
//                            mDatas13.add(new Bean("1万以下"));
//                            mDatas13.add(new Bean("1-2万"));
//                            mDatas13.add(new Bean("2-10万"));
//                            mDatas13.add(new Bean("10万以上"));
//                        }
//                        mNeedPopWindow.setData(mDatas13);
//                        if (mNeedPopWindow.mAdapter != null) {
//                            mNeedPopWindow.mAdapter.setDefItem(mNeedPopWindow.mPos13);
//                        }
//                        showPop();
                            if (priceDatas.size() == 0) {
                                mModel.getSereicePrice(2);
                            } else {
                                if (!teamForEnterpisePopWindow_price.isShowing()) {
                                    mBinding.rvSelect.smoothScrollToPosition(mAdapter.getItemCount() - 1);
                                    teamForEnterpisePopWindow_price.showPopwindow(mBinding.rvSelect, 0, 0);
                                }
                            }
                        }
                        break;
                    case 5:

                        if (type.equals("服务分类")) {
                            if (parentList.size() > 0) {
                                if (!servicePopWindow.isShowing()) {
                                    servicePopWindow.showPopwindow(mBinding.rvSelect, 0, 0);
                                }
                            } else {
                                mModel.getServiceType();
                            }
                        } else if (type.equals("服务主体")) {
                            mNeedPopWindow.mType = 14;
                            if (mDatas14 == null) {
                                mDatas14 = new ArrayList<>();
                                mDatas14.add(new Bean("不限"));
                                mDatas14.add(new Bean("团队"));
                                mDatas14.add(new Bean("企业"));
                            }
                            mNeedPopWindow.setData(mDatas14);
                            if (mNeedPopWindow.mAdapter != null) {
                                mNeedPopWindow.mAdapter.setDefItem(mNeedPopWindow.mPos14);
                            }
                            showPop();
                        } else if (type.equals("预算价格")) {

                            if (priceDatas.size() == 0) {
                                mModel.getSereicePrice(1);
                            } else {
                                if (!teamForEnterpisePopWindow_price.isShowing()) {
                                    teamForEnterpisePopWindow_price.showPopwindow(mBinding.rvSelect, 0, 0);
                                }
                            }


                        }

                        break;
                    case 6:
                        if (type.equals("资产类型")) {
                            if (assestTypeDatas.size() == 0) {
                                mModel.queryPropertyType(getContext());
                                mModel.ldList.observe(getActivity(), a -> showAssestTypePopWindow(a));
                            } else {
                                if (!typePopWindow.isShowing()) {
                                    typePopWindow.showPopwindow(mBinding.rvSelect, 0, 0);
                                }
                            }
                        } else if (type.equals("预算价格")) {
                            if (priceDatas.size() == 0) {
                                mModel.getSereicePrice(3);
                            } else {
                                if (!teamForEnterpisePopWindow_price.isShowing()) {
                                    teamForEnterpisePopWindow_price.showPopwindow(mBinding.rvSelect, 0, 0);
                                }
                            }
                        } else if (type.equals("资产新旧")) {
                            if (assestOldDatas.size() == 0) {
                                mModel.getNewOrOldType(getContext());
                                mModel.ldNewOrOldList.observe(getActivity(), a -> showAssestOldPopWindow(a));
                            } else {
                                if (!oldPopWindow.isShowing()) {
                                    oldPopWindow.showPopwindow(mBinding.rvSelect, 0, 0);
                                }
                            }
                        }
                        break;
                }
            }
        });

    }

    private void showPop() {
        mNeedPopWindow.showPopwindow(mBinding.rvSelect, 0, 0);
        mBinding.rvSelect.smoothScrollToPosition(0);
    }

    @Override
    protected void onLazyLoad() {

    }

    // 获取商标类型选项
    public void getTrademarkTypeOption(List<Bean> data) {
        mDatas1 = data;
        data.add(0, new Bean("不限"));
        mNeedPopWindow.setData(mDatas1);
        showPop();
        List<String> categoryList = new ArrayList<>();
        for (Bean entity : data) {
            categoryList.add(entity.no);
        }
        if (!TextUtils.isEmpty(category) && categoryList.size() > 0) {
            mNeedPopWindow.setDefItem(categoryList.indexOf(category));
            isChange3 = true;
            mNeedPopWindow.mPos1 = categoryList.indexOf(category);
        }
    }

    // 行业类型
    public void getAllSserviceCategory(List<Bean> data) {
        mDatas10 = data;
        data.add(0, new Bean("不限"));
        mNeedPopWindow.setData(mDatas10);
        mNeedPopWindow.showPopwindow(mBinding.rvSelect, 0, 0);
        mBinding.rvSelect.smoothScrollToPosition(0);
        List<String> categoryList = new ArrayList<>();
        for (Bean entity : data) {
            categoryList.add(entity.no);
        }
        if (!TextUtils.isEmpty(category) && categoryList.size() > 0) {
            mNeedPopWindow.setDefItem(categoryList.indexOf(category));
            isChange3 = true;
            mNeedPopWindow.mPos10 = categoryList.indexOf(category);
        }
    }

    // 获取领域分类
    public void getAllCopyright(List<Bean> data) {
        mDatas3 = data;
        data.add(0, new Bean("不限"));
        mNeedPopWindow.setData(mDatas3);
        mNeedPopWindow.showPopwindow(mBinding.rvSelect, 0, 0);
        mBinding.rvSelect.smoothScrollToPosition(0);
    }

    // 获取所有版权
    public void getAllQualification(List<Bean> data) {
        mDatas7 = data;
        data.add(0, new Bean("不限"));
        mNeedPopWindow.setData(mDatas7);
        showPop();
        List<String> categoryList = new ArrayList<>();
        for (Bean entity : data) {
            categoryList.add(entity.no);
        }
        if (!TextUtils.isEmpty(category) && categoryList.size() > 0) {
            mNeedPopWindow.setDefItem(categoryList.indexOf(category));
            isChange3 = true;
            mNeedPopWindow.mPos7 = categoryList.indexOf(category);
        }
    }


    public void getPatentTypeOption(List<Bean> data) {
        mDatas4 = data;
        data.add(0, new Bean("不限"));
        mNeedPopWindow.setData(mDatas4);
        showPop();
        List<String> categoryList = new ArrayList<>();
        for (Bean entity : data) {
            categoryList.add(entity.id);
        }
        if (!TextUtils.isEmpty(category) && categoryList.size() > 0) {
            mNeedPopWindow.setDefItem(categoryList.indexOf(category));
            isChange3 = true;
            mNeedPopWindow.mPos4 = categoryList.indexOf(category);
        }
    }

    // 需求大厅列表
    public void getDemandHallList(List<ListBean> data) {
        mBinding.displayView.refreshComplete();
        if (mIndexPage == 1) {
            mBinding.displayView.setVisibility(data.size() != 0 ? View.VISIBLE : View.VISIBLE);
            mBinding.errorView.setVisibility(data.size() != 0 ? View.GONE : View.VISIBLE);
//            ((TextView)mBinding.errorView.findViewById(R.id.no_data_tv)).setText("空空如也");
//            mBinding.errorView.findViewById(R.id.no_data_count).setVisibility(data.size() != 0 ? View.GONE : View.VISIBLE);
            mNeedAdapter.setDatas(data);
            mBinding.displayView.setLoadingMoreEnabled(true);
        } else {
            if (data.size() != 0) {
                mBinding.displayView.loadMoreComplete();
                mNeedAdapter.addDatas(data);
            } else {
                mBinding.displayView.setNoMore(true);
            }
        }
        mNeedAdapter.notifyDataSetChanged();
        if (!TextUtils.isEmpty(category)) {
            if (mIndex == 2) {
                mScreenTextView = (ScreenTextView) mBinding.rvSelect.getChildAt(1);
            } else {
                mScreenTextView = (ScreenTextView) mBinding.rvSelect.getChildAt(0);
            }
            mScreenTextView.contentSelectRed(true, false);
            isChange3 = true;
        }
    }


    public void showMakeupPopWindow(List<IpPickSelectEntity> makeupDatas) {
        List<IpPickSelectEntity> listChange = new ArrayList<>();
        listChange = PickPriceUtils.showPriceList(makeupDatas);
        this.priceDatas = listChange;
        teamForEnterpisePopWindow_price.showPopwindow(mBinding.rvSelect, 0, 0);
        teamForEnterpisePopWindow_price.setData(listChange);
        mBinding.rvSelect.smoothScrollToPosition(mAdapter.getItemCount() - 1);
    }

    public void showAssestTypePopWindow(List<IpPickSelectEntity> datas) {
        this.assestTypeDatas = datas;
        typePopWindow.setData(datas);
        typePopWindow.showPopwindow(mBinding.rvSelect, 0, 0);
        List<String> categoryList = new ArrayList<>();
        for (IpPickSelectEntity entity : datas) {
            categoryList.add(entity.getValue());
        }
        if (!TextUtils.isEmpty(category) && categoryList.size() > 0) {
            typePopWindow.setDefItem(categoryList.indexOf(category));
            ischange5 = true;
        }
    }

    public void showAssestOldPopWindow(List<IpPickSelectEntity> datas) {
        this.assestOldDatas = datas;
        oldPopWindow.setData(datas);
        oldPopWindow.showPopwindow(mBinding.rvSelect, 0, 0);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
    public void onEvent(LoginEvent event) {
        if (event.getMessageTag() == EventConstant.EVENT_NEED_FRG_JUMP) {
            mIndexPage = 1;
            mMap.put("pageSize", mIndexPage);
            mModel.getDemandHallList(mMap);
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
    public void onEvent(SearchEvent event) {
        if (event.getMessageTag() == EventConstant.EVENT_SERVICE_SEARCH) {
            String searchParam = (String) event.getMessageData();
            mIndexPage = 1;
            mMap.put("pageSize", mIndexPage);
            mMap.put("searchParam",searchParam);
            mModel.getDemandHallList(mMap);
        }
    }

    public void showServiceWindow(List<ParentAreaEntity<List<ParentAreaEntity<List<ParentAreaEntity>>>>> list) {
        this.parentList = list;
        servicePopWindow.showPopwindow(mBinding.rvSelect, 0, 0);
        servicePopWindow.setData(parentList);
        List<String> categoryList = new ArrayList<>();
        for (ParentAreaEntity entity : list) {
            categoryList.add(entity.getId());
        }
        if (!TextUtils.isEmpty(category) && categoryList.size() > 0) {
            servicePopWindow.setFirstPosition(categoryList.indexOf(category));
            ischange4 = true;
            mNeedPopWindow.mPos14 = categoryList.indexOf(category);
            mMap.put("categoryFirstId", categoryFirstId);
        }
    }


}